package com.hangxiang.approval.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hangxiang.approval.common.IntegerCommon;
import com.hangxiang.approval.common.TempTypeInsertCommon;
import com.hangxiang.approval.common.TempTypeUpdateCommon;
import com.hangxiang.approval.dao.TempTypeDao;
import com.hangxiang.approval.entity.TempType;
import com.hangxiang.approval.service.TempTypeService;
import com.hangxiang.approval.vo.TempTypeVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;


/**
 * (TempType)表服务实现类
 *
 * @author makejava
 * @since 2020-12-01 14:11:49
 */
@Service("tempTypeService")
public class TempTypeServiceImpl extends ServiceImpl<TempTypeDao, TempType> implements TempTypeService {
    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    private TempTypeDao tempTypeDao;

    /**
     * 通过ID查询单条数据
     *
     * @param common 主键
     * @return 实例对象
     */
    @Override
    public TempTypeVo queryById(IntegerCommon common) {
        TempTypeVo vo = new TempTypeVo();
        TempType tempType = tempTypeDao.selectById(common.getValue());
        BeanUtils.copyProperties(tempType, vo);
        return vo;
    }


    /**
     * 新增数据
     *
     * @param tempTypeInsertCommon 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional
    public Integer insertTempType(TempTypeInsertCommon tempTypeInsertCommon) {
        TempType tempType = new TempType();
        tempType.setCreateTime(new Date());
        tempType.setTypeName(tempTypeInsertCommon.getTypeName());
        tempType.setIsDeleted(0);
        tempTypeDao.insert(tempType);
        return tempType.getId();
    }

    /**
     * 修改数据
     *
     * @param tempTypeUpdateCommon 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional
    public Integer updateTempType(TempTypeUpdateCommon tempTypeUpdateCommon) {
        TempType tempType = new TempType();
        BeanUtils.copyProperties(tempTypeUpdateCommon, tempType);
        tempTypeDao.updateById(tempType);
        return tempType.getId();
    }

    @Override
    public List<TempType> selectAllType() {
        List<TempType> tempTypeList=tempTypeDao.selectList(new QueryWrapper<TempType>());
        return tempTypeList;
    }
}